#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[10001];
	int sum1 = 0;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
		sum1 += a[i];
	}
	int sum = 0;
	for(int i = 1 ; i <= n ; i++){
		sort(a + i , a + n + 1);
		a[i + 1] = a[i] + a[i + 1];
		sum += a[i + 1];
	}
	cout << sum - sum1 << endl;
	return 0;
}
